	<?php
		$id="";
		$name="";
		$alias="";
		$parent=0;
		$order=1;
		$link="#";
		$icon="";
		$url="add_menu";
		foreach($data->result() as $row){
			$id=$row->menu_id;
			$name=$row->name;
			$alias=$row->alias;
			$parent=$row->parent;
			$order= str_replace($parent.'0',"",$row->order);
			$id_access=$row->id_access;
			$link=$row->link;
			$icon = $row->icon;
		}
	?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
         <!-- BEGIN PAGE CONTAINER-->        
         <div class="container-fluid">
            <!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12"> 
					<!-- BEGIN PAGE TITLE & BREADCRUMB-->			
					<h3 class="page-title">
						Form Menu <small> menambah dan mengedit menu</small>
					</h3>
					<ul class="breadcrumb">
						<li>
							<i class="icon-cogs"></i>
							Pengaturan		
							<i class="icon-angle-right"></i>
						</li>
						<li>
							<a href="<?php echo base_url()?>menu">Menu</a>		
							<i class="icon-angle-right"></i>
						</li>
						<li>Form Menu</li>	
					</ul>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
            </div>
            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->          
            <div class="row-fluid">
               <div class="span12">
                  <!-- BEGIN SAMPLE TABLE PORTLET-->
                  <div class="portlet box green">
                     <div class="portlet-title">
                        <div class="caption"><i class="icon-cogs"></i>Form Menu</div>
                     </div>
                     <div class="portlet-body form">
                        <form id="form-menu" class="horizontal-form" action="<?php echo base_url()."menu/form/".encode($id)?>" method="post">

							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Name:</label>
										<div class="controls">
											<input class="m-wrap span10" id="name" type="text" value="<?php echo $name?>" name="data[name]" required />
										</div>
									</div>
								</div>
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Alias:</label>
										<div class="controls">
											<input class="m-wrap span10" id="alias" type="text" value="<?php echo $alias?>" name="data[alias]" required />
										</div>
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Icon:</label>
										<div class="controls">
											<input class="m-wrap span10" id="icon" type="text" value="<?php echo $icon?>" name="data[icon]" />
										</div>
									</div>
								</div>
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Id Access:</label>
										<div class="controls">
											<input  type="digits" class="m-wrap span10" id="id_access" value="<?php echo $id_access?>" name="data[id_access]" required/>
										</div>
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Parent :</label>
										<div class="controls">
											<select id="parent" name="data[parent]" style="width:75%;">
												<option value="0">Root</option>
												<?php
													function menu_list($menu,$parent,$count=0){
														$grs="";
														for($i=0;$i<$count;$i++)
															$grs .=" |--- ";
														foreach($menu as $row){		
															foreach($row as $key=>$value){
																if($key == 'data'){
																	echo "<option value='$value[menu_id]' ".($value['menu_id']==$parent?'selected="selected"':'').">$grs $value[alias]</option>";
																}else{
																	if(count($value) > 0){
																		menu_list($value,$parent,$cnt = $count+1);
																	}
																}
															}
														}
													}
												menu_list($menu,$parent);
												?>
											</select>
										</div>
									</div>
								</div>
								<div class="span6">
									<div class="control-group">
										<label class="control-label" >Order :</label>
										<div class="controls">
											<input  type="digits" class="m-wrap span10" id="order" value="<?php echo $order?>" name="data[order]" required/>
										</div>
									</div>
								</div>
							</div>
							<div class="row-fluid">
								<div class="span12">
									<div class="control-group">
										<label class="control-label" >Link :</label>
										<div class="controls">
											<input  type="text" class="m-wrap span11" id="link" value="<?php echo $link ?>" name="data[link]" required/>
										</div>
									</div>
								</div>
							</div>
							<div class="form-actions">
							   <button type="submit" class="btn blue"><i class="icon-ok"></i> SIMPAN</button>
							   <a href="<?php echo base_url()?>menu" class="btn">BATAL</a>
							</div>
						</form>
                     </div>
                  </div>
                  <!-- END SAMPLE TABLE PORTLET-->
               </div>              
            </div>
           
            <!-- END PAGE CONTENT-->
         </div>
         <!-- END PAGE CONTAINER-->
    </div>
    <!-- END PAGE -->
	<script>
		$(document).ready(function(){
			$("#form-menu").validate(
				{
					errorElement: 'span', //default input error message container
					errorClass: 'help-inline', // default input error message class
					focusInvalid: false, // do not focus the last invalid input
					ignore: "",
					highlight: function (element) { // hightlight error inputs
						$(element)
							.closest('.help-inline').removeClass('ok'); // display OK icon
						$(element)
							.closest('.control-group').removeClass('success').addClass('error'); // set error class to the control group
					},

					unhighlight: function (element) { // revert the change dony by hightlight
						$(element)
							.closest('.control-group').removeClass('error'); // set error class to the control group
					},

					success: function (label) {
						label
							.addClass('valid').addClass('help-inline ok') // mark the current input as valid and display OK icon
						.closest('.control-group').removeClass('error').addClass('success'); // set success class to the control group
					}
				}
			);
		});
	</script>